package com.agent.user.feign;

import cn.hutool.core.bean.BeanUtil;
import com.agent.common.result.ApiResponse;
import com.agent.user.api.feign.UserFeignClient;
import com.agent.user.api.resp.UserResp;
import com.agent.user.entity.User;
import com.agent.user.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * @author Jeff_Wan
 * @description
 * @date 2025-08-08 16:52
 */
@Slf4j
@RestController
@RequiredArgsConstructor
public class UserFeignClientImpl implements UserFeignClient {

    private final UserService userService;

    @Override
    public ApiResponse<UserResp> getUserById(Long userId) {
        User user = userService.getUserById(userId);
        return ApiResponse.success(BeanUtil.copyProperties(user, UserResp.class));
    }

    @Override
    public ApiResponse<UserResp> getUserByEmail(String email) {
        User user = userService.getUserByEmail(email);
        return ApiResponse.success(BeanUtil.copyProperties(user, UserResp.class));
    }

    @Override
    public ApiResponse<UserResp> getUserByUsername(String username) {
        User user = userService.getUserByUsername(username);
        return ApiResponse.success(BeanUtil.copyProperties(user, UserResp.class));
    }

    @Override
    public ApiResponse<UserResp> createOrUpdateByGoogleId(String googleId, String email, String username, String avatarUrl) {
        User user = userService.createOrUpdateByGoogleId(googleId, email, username, avatarUrl);
        return ApiResponse.success(BeanUtil.copyProperties(user, UserResp.class));
    }

    @Override
    public ApiResponse<UserResp> updateMembership(Long userId, String planType, String subscriptionType,
                                                  LocalDateTime startDate, LocalDateTime endDate) {
        userService.updateMembership(userId, planType, subscriptionType, startDate, endDate);
        return ApiResponse.success();
    }


}
